package com.tiheima.controller;

import com.tiheima.model.dos.StuListDO;
import com.tiheima.model.dto.student.StuPageQuery;
import com.tiheima.model.dto.student.StuAddDTO;
import com.tiheima.model.dto.student.StuUpdataDTO;
import com.tiheima.model.result.PageResult;
import com.tiheima.model.result.Result;
import com.tiheima.model.vo.GetStuByIdVO;
import com.tiheima.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping
    public Result<PageResult<StuListDO>> page(StuPageQuery query) {
        return Result.success(studentService.page(query));
    }

    //students/1,2,3
    // /students/{ids}
    @DeleteMapping("/{ids}")
    public Result<?> deleteStu(@PathVariable("ids") ArrayList<String> ids) {
        // @TODO 接收不到数据
        System.out.println(ids);
        studentService.deleteStu(ids);
        return Result.success();
    }

    @PostMapping
    public Result<?> addStu(@RequestBody StuAddDTO stuAddDTO) {
        studentService.addStu(stuAddDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<GetStuByIdVO> getStuById(@PathVariable("id") Integer id) {
        GetStuByIdVO getStuByIdVO = studentService.getStuById(id);
        return Result.success(getStuByIdVO);
    }

    @PutMapping
    public Result<?> updateStu(@RequestBody StuUpdataDTO stuUpdataDTO) {
        studentService.updateStu(stuUpdataDTO);
        return Result.success();
    }


    @PutMapping("/violation/{id}/{score}")
    public Result<?> violation(@PathVariable("id") Integer id, @PathVariable("score") Integer score) {
        studentService.violation(id, score);
        return Result.success();
    }
}
